/***************************************************************************
 *   Copyright (C) 2011  by TinySofts                                      *
 *   tinysofts@gmail.com                                                   *
 *   All Rights Reserved.                                                  *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   Refer to http://code.google.com/p/tinydict/                           *
 ***************************************************************************/

/*
    .dz Lib
    Status:Open;ReleaseReady;M
*/

#ifndef DICTZIP_H
#define DICTZIP_H

#include <QtCore>

class _Chunk
{
public:
    int chkpos;
    int chklen;
};

class DictZip
{
public:
    DictZip(QString dict);

public:
    int errorNo;
    QByteArray read(int size);
    int read(int size, char * buff);
    bool seek(int offset);

private:
    QString dictName;
    QFile fileHandler;

    int _lastpos; /*deflate data last position in .dz*/
    int _firstpos; /*deflate data first position in .dz*/
    int pos; /*current position of `uncompressed` file*/
    int chunkNum; /*chunk numbers*/
    int chunkSize; /*default chunk size*/

    QList<_Chunk> chunks; /**/
    void _readHeader();
    QByteArray _readChunk(int chunkid);
    int _readChunk(int chunkid, char * buff);

    static const int FTEXT = 1;
    static const int FHCRC = 2;
    static const int FEXTRA = 4 ;
    static const int FNAME = 8;
    static const int FCOMMENT = 16;
};

#endif // DICTZIP_H
